package com.heima.admin.controller.v1;

import com.heima.admin.service.ChannelService;
import com.heima.model.admin.dtos.ChannelDTO;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "频道管理controller",tags = "频道管理controller")
@RestController
@RequestMapping("api/v1/channel")
public class AdChannelController {

    @Autowired
    public ChannelService channelService;

    @ApiOperation(value = "根据条件分页查询",notes = "根据条件： name status 进行查询，结果以ord升序排序")
    @PostMapping("/list")
    public PageResponseResult PageResponseResult(@RequestBody ChannelDTO dto,@RequestHeader(value = "userId",required = false) String id) {
        System.out.println("当前登录用户id："+id);

        return channelService.findByNameAndPage(dto);
    }

    @ApiOperation(value = "新增频道",notes = "新增频道")
    @PostMapping("/save")
    public ResponseResult insert(@RequestBody AdChannel adChannel){
        return channelService.insert(adChannel);
    }

    @ApiOperation(value = "修改频道",notes = "修改频道")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel adChannel){
        return channelService.updateChannel(adChannel);
    }

    @ApiOperation(value = "删除频道",notes = "删除频道")
    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id){
        return channelService.deleteChannel(id);
    }

}
